package com.baizhi.service.impl;

import com.baizhi.dao.AdminDAO;
import com.baizhi.entity.Admin;
import com.baizhi.service.AdminService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminDAO adminDAO;

    @Override
    public Boolean login(Admin admin) {
        Admin admin1 = adminDAO.selectByUsername(admin.getUsername());
        if (admin1 != null && admin.getPassword().equalsIgnoreCase(admin1.getPassword())){
            return true;
        }else {
            return false;
        }


    }

    @Override
    public Admin showByName(String username) {
        return adminDAO.selectByUsername(username);
    }

    @Override
    public Admin showById(int id) {
        return adminDAO.selectByid(id);
    }

    @Override
    public PageInfo<Admin> showAll(int page,int limit,String username) {
        PageHelper.startPage(page, limit);
        List<Admin> admins = adminDAO.selectAll(username);
        PageInfo<Admin> pageInfo = new PageInfo<>(admins);
        return pageInfo;
    }

    @Override
    public void add(Admin admin) {
        adminDAO.insertAdmin(admin);
    }

    @Override
    public void remove(int id) {
        adminDAO.deleteById(id);
    }

    @Override
    public void update(Admin admin) {
        adminDAO.updateAdmin(admin);
    }
}


